var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    info: [],
    lock: false
  },
  onLoad: function(options) {},
  onReady: function() {},
  onShow: function() {
    var _this = this
    _this.onUserlist()
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  //验光师列表
  onUserlist() {
    var _this = this
    com.link(app.link.optiometUser, {}, function(res) {
      console.log(res)
      _this.setData({
        info: res.data.data
      })
    }, 'GET')
  },
  dsds(e) {
    console.log(e);
    var _this = this
    if (_this.data.lock) {
      //开锁
      setTimeout(() => {
        _this.setData({
          lock: false
        });
      }, 100);
    }
  },
  onPullUser(e) {
    console.log(e)
    var _this = this,
      id = e.currentTarget.dataset.id
    if (this.data.lock) {
      return false;
    }
    if (id == 2) {
      var uid = e.currentTarget.id
      wx.navigateTo({
        url: '/pages/onPullUser/onPullUser?id=' + id + '&uid=' + uid + '&name=' + e.currentTarget.dataset.name + '&cover=' + e.currentTarget.dataset.cover + '&cover_url=' + e.currentTarget.dataset.cover_url,
      })
    } else {
      wx.navigateTo({
        url: '/pages/onPullUser/onPullUser?id=' + e.currentTarget.dataset.id,
      })
    }
  },
  //删除验光师
  deleteUser(e) {
    var _this = this
    _this.setData({
      lock: true
    });
    wx.showModal({
      title: '温馨提示',
      content: '确认删除此验光师吗？',
      success(res) {
        if (res.confirm) {
          com.link(app.link.deleteUser + e.currentTarget.id + '.st', {}, function(res) {
            console.log(res)
            if (res.data.state) {
              wx.showToast({
                title: '删除成功',
                icon: 'success'
              })
              setTimeout(() => {
                _this.onUserlist()
              }, 1500);
            } else {
              wx.showModal({
                title: '温馨提示',
                content: res.data.message,
              })
            }
          })
        }
      }
    })
  },

})